import * as API from "../../utils/findUrl"
import * as actionType from "../types/find"
import {RES_OK_CODE} from "../types/index" 

import {post} from "../../utils/url"

export function loadActivityCenter(){
  return (dispatch, getState) => {
    post(API.loadActivityCenterAPI())
    .then(res => res.json())
    .then(data => {
        dispatch({
          type: actionType.REQUEST_ACTIVITY_CENTER,
          data: data
        });
    });
  };
}

export function loadNewList(){
  return (dispatch, getState) => {
    post(API.loadNewListAPI())
    .then(res => res.json())
    .then(data => {
        dispatch({
          type: actionType.REQUEST_NEWS_LIST,
          data: data
        });
    });
  };
}

export function loadNewItem(id,cb=()=>{}){
  return (dispatch, getState) => {
    post(API.loadNewItemAPI(),{id})
    .then(res => res.json())
    .then(data => {
        cb(data)
    });
  };
}


export function loadPlayList(ruleCode){
  return (dispatch, getState) => {
    post(API.loadPlayListAPI(),{
      ruleType:"cp_rule_type",
      ruleCode
    })
    .then(res => res.json())
    .then(data => {
        dispatch({
          type: actionType.REQUEST_PLAY_LIST,
          data
        })
    })
  }
}
